
package com.eyedog.uilibrary.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述 通用ViewPager适配器基类
 *
 * @author walljiang
 * @since 2017/3/7 11:26
 */

public class BaseFragmentPagerAdapter extends FragmentPagerAdapter {

    private List<? extends Fragment> mFragments = new ArrayList<>();

    private List<String> titles;

    public BaseFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addFragments(List<? extends Fragment> fragments) {
        mFragments = fragments;
    }

    public void setTabTitles(List<String> titles) {
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (titles != null) {
            return titles.get(position);
        }
        return "";
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }
}
